function MilReservas()
{
    this.activeButtons = function()
    {
        $(".fg-button:not(.ui-state-disabled)")
                .hover(
                    function(){
                        $(this).addClass("ui-state-hover");
                    },
                    function(){
                        $(this).removeClass("ui-state-hover");
                    }
                )
    }

    this.deleteDialog = function(title,message, el)
    {
        var dialogHtml = '<div id="confirmDialog" title="'+title+'"><div id="confirmDialogContent">'+message+'</div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#confirmDialog').dialog({
            bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
            close: function(event, ui) {$("#confirmDialog").remove(); },
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Aceptar': function() {
					$(this).dialog('close');
                    //window.location = el.href;
                    el();
				},
				'Cancelar': function() {
					$(this).dialog('close');
                    return false;
				}
			}
            
            })

        $('#confirmDialog').dialog('open');
        return false;
    }

    this.addUnitDialog = function(title, message,idDescriptionUnit)
    {
        var dialogHtml = '<div id="addUnitDialog" title="'+title+'"><div id="addUnitDialogContent">'+message+'<br/><input id="nameUnit" value="" /></div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#addUnitDialog').dialog({
            bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
            close: function(event, ui) {$("#addUnitDialog").remove(); },
			buttons: {
				'Aceptar': function() {
					var newname = $('#nameUnit').val();

                    $.post("/system/accommodation/addbookingunit",
                        {nameunit: newname, descriptionunit: idDescriptionUnit},
                        function(html)
                        {
                            $("#addUnitDialog").remove();
                            //Esta funcion esta en la vista editdescriptionunit
                            addUnit(html,newname);
                        }
                    );
                    
				},
				'Cancelar': function() {
					$(this).dialog('close');
                    return false;
				}
			}

            })

        $('#addUnitDialog').dialog('open');
        return false;
    }

    this.infoDialog = function(title,message)
    {
        var dialogHtml = '<div id="infoDialog" title="'+title+'"><div id="infoDialogContent"><img src="/img/icons/information.png" style="vertical-align:top;" />&nbsp;'+message+'</div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#infoDialog').dialog({
            bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
            close: function(event, ui) {$("#infoDialog").remove(); },
			buttons: {
				'Cerrar': function() {
					$(this).dialog('close');
                    }
			}
        });

        $('#infoDialog').dialog('open');
        return false;
    }

    this.getButtonUrlDialog = function(title,idDescriptionUnit)
    {
        var dialogHtml = '<div id="buttonUrlDialog" title="'+title+'"><div id="buttonUrlDialogContent"></div></div>';
        $('body').append(dialogHtml);

        // Dialog 
        $('#buttonUrlDialog').dialog({
            bgiframe: true,
			resizable: false,
			modal: true,
            open: function(event, ui){ $('#buttonUrlDialogContent').load('/system/tools/getbuttonurl?descriptionunit='+idDescriptionUnit); },
            close: function(event, ui) {$("#buttonUrlDialog").remove(); },
			buttons: {
				'Cerrar': function() {
					$(this).dialog('close');
                    return false;
				}
			}

            })

        $('#buttonUrlDialog').dialog('open');
        return false;
    }

    this.getButtonCodeDialog = function(title,idDescriptionUnit)
    {
        var dialogHtml = '<div id="buttonCodeDialog" title="'+title+'"><div id="buttonCodeDialogContent"></div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#buttonCodeDialog').dialog({
            bgiframe: true,
			resizable: false,
            height:400,
            width:325,
			modal: true,
            open: function(event, ui){ $('#buttonCodeDialogContent').load('/system/tools/getbuttoncode?descriptionunit='+idDescriptionUnit); },
            close: function(event, ui) {$("#buttonCodeDialog").remove(); },
			buttons: {
				'Cerrar': function() {
					$(this).dialog('close');
                    return false;
				}
			}

            })

        $('#buttonCodeDialog').dialog('open');
        return false;
    }

    this.getButtonEmailDialog = function(title,idDescriptionUnit)
    {
        var dialogHtml = '<div id="buttonEmailDialog" title="'+title+'"><div id="buttonEmailDialogContent"></div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#buttonEmailDialog').dialog({
            bgiframe: true,
			resizable: true,
            height:380,
            width:340,
			modal: true,
            open: function(event, ui){ $('#buttonEmailDialogContent').load('/system/tools/getsendbyemail?descriptionunit='+idDescriptionUnit); },
            close: function(event, ui) {$("#buttonEmailDialog").remove(); }
            })

        $('#buttonEmailDialog').dialog('open');
        return false;
    }

    this.changePasswordDialog = function(title, message)
    {
        var dialogHtml = '<div id="changePasswordDialog" title="'+title+'"><div id="changePasswordDialogContent">'+message+'<br/><input type="password" id="newpassword" value="" /></div></div>';
        $('body').append(dialogHtml);

        // Dialog
        $('#changePasswordDialog').dialog({
            bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
            close: function(event, ui) {$("#changePasswordDialog").remove(); },
			buttons: {
				'Aceptar': function() {
					var newpassword = $('#newpassword').val();
                    
                    $.post("/system/index/setpassword",
                        {password: newpassword},
                        function(html)
                        {
                            $("#changePasswordDialog").remove();

                            $.gritter.add({
                                title: 'Cambiar clave',
                                text: 'La clave ha sido modificada con exito',
                                time: 2000
                            });
                        }
                    );

				},
				'Cancelar': function() {
					$(this).dialog('close');
                    return false;
				}
			}

            });

        $('#changePasswordDialog').dialog('open');
        return false;
    }


}

jQuery.MR = new MilReservas();

function runEffectToggle( id )
{
    var selectedEffect = 'blind';
    var options = {};
    $("#"+id).toggle(selectedEffect,options,500);
}

function numberOfDays(checkin, checkout)
{
    var day = 86400000;

	var chkin = checkin.split('-');
	var chkout = checkout.split('-');

	var dateIn  = new Date();
	dateIn.setFullYear(chkin[0],chkin[1]-1,chkin[2]);

	var dateOut = new Date()
	dateOut.setFullYear(chkout[0],chkout[1]-1,chkout[2]);

	if( dateOut.getTime() > dateIn.getTime()  )
		return Math.floor( (dateOut.getTime() - dateIn.getTime())/day );

	return -1;
}


